package com.jn.moduledemo.common.base;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.fragment.app.Fragment;

import com.jn.moduledemo.common.custom.CustomToast;

public abstract class BaseFragment extends Fragment {
    private static final int FAST_CLICK_INTERVAL = 500;//快速点击间隔
    private long lastClickTime;//last click time
    private CustomToast mToast;
    protected View mView;
    public Context mContext;

    protected abstract int getLayoutId();

    protected abstract void init();

    protected abstract void onFragmentChanged();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mView = inflater.inflate(getLayoutId(), container, false);
        init();
        return mView;
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        mContext = context;
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if (!hidden) {
            onFragmentChanged();
        }
    }

    public void showToast(int id) {
        String str = getString(id);
        showToast(str);
    }

    public void showToast(String text) {
        if (!TextUtils.isEmpty(text)) {
            if (mToast == null) {
                mToast = new CustomToast(getActivity());
            }
            mToast.setDuration(Toast.LENGTH_LONG);
            mToast.setText(text);
            mToast.show();
        }
    }

    public abstract void onClick(View v);
}
